<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<form method="post" class="form-inline m-b-xs" action="<?php echo url('report-channel');?>">
	<div class="row">
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">
				<select name="type" class="form-control" style="width:100%;">
					<option value="0" <?php if($type==0){echo 'selected';} ?>>通道</option>
					<option value="1" <?php if($type==1){echo 'selected';} ?>>支付宝账号</option>
					<option value="2" <?php if($type==2){echo 'selected';} ?>>姓名</option>
				</select>
			</div>
		</div>		
		<div class="col-lg-3">
			<div class="form-group" style="width:100%;">
				<input type="text" class="form-control" name="keywords" placeholder="关键字" value="<?php echo $keywords;?>" size="15" style="width:100%;">
			</div>
		</div>
		<div class="col-lg-5">
			<div class="form-group">
				<div class="input-group" style="background-color:#fff;">
					<span class="input-group-addon"><i class="icon icon-calendar"></i></span>
					<input type="text" name="fdate" class="form_datetime form-control" value="<?php echo $fdate;?>">
					<span class="input-group-addon">至</span>
					<input type="text" name="tdate" class="form_datetime form-control" value="<?php echo $tdate;?>">
				</div>
			</div>
		</div>
		<div class="col-lg-2">
			<button type="submit" class="btn btn-success" style="width:100%;">
				<i class="icon icon-search"></i>
				立即查询
			</button>
		</div>
	</div>
</form>

<div class="row">
	<div class="col-lg-12">
	
		<h4>通道充值报表</h4>
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">通道</th>
							<th class="text-center">支付宝账号</th>
							<th class="text-center">姓名</th>
							<th class="text-center">成功交易笔数</th>
							<th class="text-center">成功交易金额</th>
							<th class="text-center">商户获得金额</th>
							<th class="text-center">代理获得金额</th>
                          	<th class="text-center">平台获得金额</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$total_nums=$total_pay=$total_merchant=$total_proxy=$total_plat=0;
						if($orders){foreach($orders as $o){
						$total_nums+=$o['nums'];
						$total_pay+=$o['coin_pay_total'];
						$total_merchant+=$o['coin_merchant_total'];
						$total_proxy+=$o['coin_proxy_total'];
						$total_plat+=$o['coin_plat_total'];
						?>
						<tr>
							<td class="text-center"><?php echo $o['name'];?></td>
							<td class="text-center"><?php echo $o['alipay_account'];?></td>
							<td class="text-center"><?php echo $o['alipay_realname'];?></td>
							<td class="text-center"><?php echo $o['nums'];?></td>
							<td class="text-center"><?php echo $o['coin_pay_total'];?></td>
							<td class="text-center"><?php echo $o['coin_merchant_total'];?></td>
							<td class="text-center"><?php echo $o['coin_proxy_total'];?></td>
							<td class="text-center"><?php echo $o['coin_plat_total'];?></td>
						</tr>
						<?php }} ?>
                      	<tr>
                          	<td class="text-center" colspan="3">合计</td>
                          	<td class="text-center"><?php echo $total_nums;?></td>
                          	<td class="text-center"><?php echo $total_pay;?></td>
							<td class="text-center"><?php echo $total_merchant;?></td>
							<td class="text-center"><?php echo $total_proxy;?></td>
							<td class="text-center"><?php echo $total_plat;?></td>
                        </tr>
					</tbody>
				</table>
			</div>
		</div>
		
		<?php if($keywords==''){?>
		<h4>提现报表</h4>
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
							<th class="text-center">成功提现笔数</th>
							<th class="text-center">成功提现总额</th>
							<th class="text-center">成功提现手续费</th>
							<th class="text-center">待审核提现笔数</th>
							<th class="text-center">待审核提现总额</th>
							<th class="text-center">待审核提现手续费</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td class="text-center"><?php echo $cashs_success['nums'];?></td>
							<td class="text-center"><?php echo $cashs_success['coin_total'];?></td>
							<td class="text-center"><?php echo $cashs_success['fee_total'];?></td>
							<td class="text-center"><?php echo $cashs_wait['nums'];?></td>
							<td class="text-center"><?php echo $cashs_wait['coin_total'];?></td>
							<td class="text-center"><?php echo $cashs_wait['fee_total'];?></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		
		<h4>计算</h4>
		<div class="card">
			<div class="table-responsive">
				<table class="table" style="min-width: 800px">
					<thead>
						<tr>
						  <th class="text-center">商户获得金额</th>
						  <th class="text-center">+</th>
						  <th class="text-center">代理获得金额</th>
						  <th class="text-center">=</th>
						  <th class="text-center">获得金额</th>
					  <th class="text-center">&nbsp;</th>
					      <th class="text-center">&nbsp;</th>
					      <th class="text-center">&nbsp;</th>
				      <th class="text-center"></th>
					  </tr>
					</thead>
					<tbody>
						<tr>
						  <td class="text-center"><?php echo $total_merchant;?></td>
						  <td class="text-center">+</td>
						  <td class="text-center"><?php echo $total_proxy;?></td>
						  <td class="text-center">=</td>
						  <td class="text-center"><?php echo $total_de=$total_merchant+$total_proxy;?></td>
						  <td class="text-center">&nbsp;</td>
						  <td class="text-center">&nbsp;</td>
						  <td class="text-center">&nbsp;</td>
						  <td class="text-center">&nbsp;</td>
					  </tr>
						<tr>
						  <th class="text-center">成功提现总额</th>
						  <th class="text-center">+</th>
						  <th class="text-center">成功提现手续费</th>
						  <th class="text-center">+</th>
						  <th class="text-center">待审核提现总额</th>
						  <th class="text-center">+</th>
						  <th class="text-center">待审核提现手续费</th>
						  <th class="text-center">=</th>
						  <th class="text-center">提现金额</th>
					  </tr>
						<tr>
						  <td class="text-center"><?php echo $cashs_success['coin_total'];?></td>
						  <td class="text-center">+</td>
						  <td class="text-center"><?php echo $cashs_success['fee_total'];?></td>
						  <td class="text-center">+</td>
						  <td class="text-center"><?php echo $cashs_wait['coin_total'];?></td>
						  <td class="text-center">+</td>
						  <td class="text-center"><?php echo $cashs_wait['fee_total'];?></td>
						  <td class="text-center">=</td>
						  <td class="text-center"><?php echo $total_ti=$cashs_success['coin_total']+$cashs_success['fee_total']+$cashs_wait['coin_total']+$cashs_wait['fee_total'];?></td>
					  </tr>
						<tr>
						  <th class="text-center">获得金额</th>
						  <th class="text-center">-</th>
						  <th class="text-center">提现金额</th>
						  <th class="text-center">-</th>
						  <th class="text-center">(今日金额</th>
						  <th class="text-center">-</th>
						  <th class="text-center">昨日金额)</th>
						  <th class="text-center">=</th>
						  <th class="text-center"><input type="button" class="btn btn-primary" id="compute" value="计算"></th>
					  </tr>
						<tr>
						  <td class="text-center" id="total_de"><?php echo $total_de;?></td>
						  <td class="text-center">-</td>
						  <td class="text-center" id="total_ti"><?php echo $total_ti;?></td>
						  <td class="text-center">-</td>
						  <td class="text-center">(<input id="money_today" value="0"></td>
						  <td class="text-center">-</td>
						  <td class="text-center"><input id="money_yestoday" value="0">)</td>
						  <td class="text-center">=</td>
						  <td class="text-center" id="result"><?php echo $total_de-$total_ti;?></td>
					  </tr>
					</tbody>
				</table>
			</div>
		</div>
		<?php }?>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>
<link rel="stylesheet" href="../view/css/datetimepicker.css?r=1">
<script src="../view/js/datetimepicker.js?r=1" type="text/javascript"></script>

<script>
//日期插件
$(".form_datetime").datetimepicker({
	language:  'zh',
	format: 'yyyy-mm-dd hh:ii:ss',//显示格式
	todayHighlight: 1,//今天高亮
	minView: 'hour',//设置只显示到月份
	startView: 'month',
	forceParse: 0,
	autoclose: 1//选择后自动关闭
});

//计算
$('#compute').click(function(){
	var result=$('#total_de').text()-$('#total_ti').text()-($('#money_today').val()-$('#money_yestoday').val());
	$('#result').text(result.toFixed(3));
});

$('#nav_pc li.report, #nav_mobile li.report').tab('show');
</script>